package com.ybxx.core.web.action;


import com.ybxx.core.web.paging.PagingBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
/**
 * 功能：Action基类
 * 公司：XA.Co.LTD
 * 制作人：Tom.Y
 * 日期：2011-05*/
public class BaseAction{
	public static final String SUCCESS = "success";
	public static final String INPUT = "input";
	private String successResultValue;
	public static final String JSON_SUCCESS = "{success:true}";
	protected String dir;
	protected String sort;
	protected Integer limit = Integer.valueOf(25);
	private String isend;//是否是最后一页，0代表已经是最后一页，非0代表不是

	protected Integer start = Integer.valueOf(0);
	protected String jsonString;
	private static final long serialVersionUID = 1L;
	protected final transient Log logger = LogFactory.getLog(getClass());
	public final String CANCEL = "cancel";

	public final String VIEW = "view";
	
	private int rownum;
	private int currentpage;
	private int pageSize;

	public String getSuccessResultValue(){
		return this.successResultValue;
	}

	public void setSuccessResultValue(String successResultValue) {
		this.successResultValue = successResultValue;
	}

	public void setJsonString(String jsonString){
		this.jsonString = jsonString;
	}

	public String getJsonString() {
		return this.jsonString;
	}

	public BaseAction() {
		setSuccessResultValue("/jsonString.jsp");
	}

	protected HttpServletRequest getRequest(){
		return ServletActionContext.getRequest();
	}

	protected HttpServletResponse getResponse(){
		return ServletActionContext.getResponse();
	}

	protected HttpSession getSession(){
		return getRequest().getSession();
	}

	protected PagingBean getInitPagingBean(){
		PagingBean pb = new PagingBean(this.start.intValue(), this.limit.intValue());
		return pb;
	}

	public String list() {
		return "success";
	}
	public String edit() {
		return "input";
	}

	public String save() {
		return "input";
	}
	public String delete() {
		return "success";
	}

	public String multiDelete() {
		return "success";
	}

	public String multiSave() {
		return "success";
	}
	public String getDir() {
		return this.dir;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}
	
	public String getSort() {
		return this.sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public Integer getLimit() {
		return this.limit;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public Integer getStart() {
		return this.start;
	}

	public void setStart(Integer start) {
		this.start = start;
	}

	public String getIsend() {
		return isend;
	}

	public void setIsend(String isend) {
		this.isend = isend;
	}

	public String execute() throws Exception {
		HttpServletRequest request = getRequest();
		String uri = request.getRequestURI();
		String url = uri.substring(request.getContextPath().length());
		url = url.replace(".do", ".jsp");
		url = "/pages" + url;

		if (this.logger.isInfoEnabled()) {
			this.logger.info("forward url:" + url);
		}
		setSuccessResultValue(url);
		return "success";
	}

	public int getRownum() {
		return rownum;
	}

	public void setRownum(int rownum) {
		this.rownum = rownum;
	}

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
}
